﻿/*----------------------------------------------------------------
// 公司名称：公司名称
// 
// 产品名称：Gaf
//
// 创 建 人：netcasewqs
// 创建日期：2022/3/4
// 邮    箱：netcasewqs@qq.com
//
// Copyright (C) 2022 Gaf，保留所有权利。
//
//----------------------------------------------------------------*/


namespace Gaf.Impl;

internal class AddinManager : IAddinManager
{
    private readonly GafImpl _gaf;

    internal AddinManager(GafImpl gaf) => _gaf = gaf;

    public IEnumerable<IAddin> Addins => _gaf.Addins.Select(p => p.Addin).ToList();

    public IDictionary<Assembly, string> AssemblyLocations => _gaf._repository.assemblyLocations.ToDictionary(p => p.Key, p => p.Value);

    public void Start(int addinID)
    {
        var addin = _gaf._repository.Activators.FirstOrDefault(p => p.Addin.Id == addinID);
        addin?.Start(_gaf.Provider);
    }

    public void Stop(int addinID)
    {
        var addin = _gaf._repository.Activators.FirstOrDefault(p => p.Addin.Id == addinID);
        addin?.Stop(_gaf.Provider);
    }

    public void Uninstall(int addinID)
    {
        var addin = _gaf._repository.Activators.FirstOrDefault(p => p.Addin.Id == addinID);
        addin?.Uninstall(_gaf.Provider);
    }
}